﻿/*  Eleven Business Suite : Un ERP básico para pequeños empresarios.
 *  Copyright (C) 2011  Francis Bolaños Arias
 *
 *  This program is free software: you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License as published by
 *  the Free Software Foundation, either version 2 of the License, or
 *  (at your option) any later version.
 *
 *  This program is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU General Public License for more details.
 *
 *  You should have received a copy of the GNU General Public License
 *  along with this program.  If not, see <http://www.gnu.org/licenses/>;.
 */

using System;
using System.Data;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using ElevenData;

namespace ElevenCore
{
    public class GENDistrito
    {       
        private int _IdDistrito;
        private int _IdCanton;
        private string _Nombre;
        private Validador valida = new Validador();

        public GENDistrito() { }

        public GENDistrito(int IdDistrito, int IdCanton, string Nombre)
        {
            this.IdDistrito = IdDistrito;
            this.IdCanton = IdCanton;
            this.Nombre = Nombre;
        }

        public int IdDistrito
        {
            get { return _IdDistrito; }
            set
            {
                if (valida.validarNumeroPositivo(value))
                {
                    _IdDistrito = value;
                }
                else
                {
                    throw new ValidadorException("El Id del distrito no puede ser negativo.");
                }
            }
        }

        public int IdCanton
        {
            get { return _IdCanton; }
            set
            {
                if (valida.validarNumeroPositivo(value))
                {
                    _IdCanton = value;
                }
                else
                {
                    throw new ValidadorException("El Id del cantón no puede ser negativo.");
                }
            }
        }

        public string Nombre
        {
            get { return _Nombre; }
            set {
                if (!valida.validarEsVacio(value))
                {
                    _Nombre = value;
                }
                else {
                    throw new ValidadorException("Debe ingresar un nombre de distrito.");
                }
            }
        }

        public bool insertar() {
            return Insertar.insertarDistritos(this.IdCanton, this.Nombre);
        }

        public bool modificar() {
            return Modificar.modificarDistritos(this.IdDistrito, this.IdCanton, this.Nombre);
        }

        public bool eliminar() {
            return Eliminar.eliminarDistritos(this.IdDistrito);
        }

        public static DataTable consultar(int IdCanton) {
            return Consultar.ConsultarDistritos(IdCanton);
        }

    }
}

